//结合axios 请求后台数据,存入pinia 给各个组件都能使用
import { defineStore } from 'pinia'
import axios from 'axios'
import { onMounted, ref, reactive } from 'vue'

//export const useMoviesStore = defineStore('movieStore',{}) //vue2
export const useMoviesStore = defineStore('movieStore', () => {
  const movies = reactive([])

  const init = async () => {
    const url = 'http://localhost:8080/movie/movie_json' //本机能跑通的地址
    const { data } = await axios.post(url)
    movies.push(...data) //movies.lenth
    console.log('init--', movies)
  }

  onMounted(() => {
    init()
  })
  return { movies }
}) //vue3
